﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SageKing.Application.AspNetCore.SqlSugar.Extensions;

public static class SysSageKingMessageAttributeExts
{

    public static Dictionary<DataStreamTypeEnum, Dictionary<string, byte>> GetPosDic<T>(this SysSageKingMessageBase<T> message)
        where T : SysSageKingMessageAttributeBase
    {
        var data = message.Children.GroupBy(a => a.Type).ToList();
        var result = new Dictionary<DataStreamTypeEnum, Dictionary<string, byte>>();
        foreach (var item in data)
        {
            var data2 = item.Select(a => a.Name).OrderBy(a => a);
            var data2Dic = new Dictionary<string, byte>();
            byte sort = 0;
            foreach (var item2 in data2)
            {
                data2Dic[item2] = sort;
                sort++;
            }
            result[item.Key.GetArr()] = data2Dic;
        }
        return result;
    }
    public static DataStreamTypeEnum GetArr(this DataStreamTypeEnum data)
    {
        switch (data)
        {
            case DataStreamTypeEnum.String:
                return DataStreamTypeEnum.StringArr;
            case DataStreamTypeEnum.Int8:
                return DataStreamTypeEnum.Int8Arr;
            case DataStreamTypeEnum.Uint8:
                return DataStreamTypeEnum.Uint8Arr;
            case DataStreamTypeEnum.Int16:
                return DataStreamTypeEnum.Int16Arr;
            case DataStreamTypeEnum.Uint16:
                return DataStreamTypeEnum.Uint16Arr;
            case DataStreamTypeEnum.Int32:
                return DataStreamTypeEnum.Int32Arr;
            case DataStreamTypeEnum.Uint32:
                return DataStreamTypeEnum.Uint32Arr;
            case DataStreamTypeEnum.Int64:
                return DataStreamTypeEnum.Int64Arr;
            case DataStreamTypeEnum.Uint64:
                return DataStreamTypeEnum.Uint64Arr;
            case DataStreamTypeEnum.Float32:
                return DataStreamTypeEnum.Float32Arr;
            case DataStreamTypeEnum.Float64:
                return DataStreamTypeEnum.Float64Arr;
            default:
                return data;
        }
    }
}
